//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.das.cloudmetro.ssoserver.rs.filter;

import com.das.framework.common.utils.ContextHandler;
import java.io.IOException;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.ext.Provider;

import org.jboss.resteasy.core.ResteasyContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
@Provider
public class ApplicationResponseFilter implements ContainerResponseFilter {

    protected static Logger log = LoggerFactory.getLogger(ApplicationResponseFilter.class);

    public ApplicationResponseFilter() {
    }

    public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {

        ContextHandler.remove();

        // 清理 上下文中保存的信息
        ResteasyContext.clearContextData();

        long startTime = Long.parseLong(requestContext.getProperty("start_time").toString());

        log.info("jaxrs reqponse filter, handle time (ms): " + (System.currentTimeMillis() - startTime));

        if (requestContext.getHeaderString("ping") != null) {
            responseContext.getHeaders().add("pong", "pong");
        }

    }
}
